package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 梦龙
 * @date 2023/12/6 13:52
 */

@Mapper
public interface ShoppingCartMapper {

    /**
     * @description:动态条件查询sql
     * @return: java.util.List<com.sky.entity.ShoppingCart>
     * @author: 梦龙
     * @time: 2023/12/6 13:56
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * @description:通过id更新购物车中商品的数量
     * @return: void
     * @author: 梦龙
     * @time: 2023/12/6 14:31
     */
    @Update("update sky_take_out.shopping_cart set number = #{number} where id = #{id} ")
    void updateNumberById(ShoppingCart cart);

    /**
     * @description:插入购物车数据
     * @return: void
     * @author: 梦龙
     * @time: 2023/12/6 15:11
     */
    @Insert("insert into sky_take_out.shopping_cart (`name`, image, user_id, dish_id, setmeal_id, dish_flavor, `number`, amount, create_time) " +
            "values " +
            "(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * @description:根据userId删除购物车数据
     * @return: void
     */
    @Delete("delete from sky_take_out.shopping_cart where user_id = #{userId}")
    void deleteByUserId(Long userId);

    @Delete("delete from sky_take_out.shopping_cart where id = #{id}")
    void deleteById(ShoppingCart cart);
}
